package com.sunwayhorizo.health.platform.security.persistent;

import java.util.ArrayList;
import java.util.List;

import javax.persistence.CascadeType;
import javax.persistence.Column;
import javax.persistence.Entity;
import javax.persistence.FetchType;
import javax.persistence.GeneratedValue;
import javax.persistence.GenerationType;
import javax.persistence.Id;
import javax.persistence.JoinColumn;
import javax.persistence.ManyToOne;
import javax.persistence.OneToMany;
import javax.persistence.Table;
import javax.persistence.TableGenerator;

import com.sunwayhorizo.health.platform.util.BeanHelper;

@Entity
@TableGenerator(name = "SecurityPermission_IdGenerator", table = "ET_Id_Generator", pkColumnName = "pkColumn", valueColumnName = "valueColumn", pkColumnValue = "SECURITY_PERMISSION_ID",allocationSize=25)
@Table(name = "SECURITY_PERMISSION", schema = "ETS")
public class SecurityPermission implements java.io.Serializable {
	
	@Id
	@GeneratedValue(strategy = GenerationType.TABLE, generator = "SecurityPermission_IdGenerator")
	@Column(name = "PERMISSION_ID", unique = true, nullable = false, length = 32)
	private String permissionId;
	
	@ManyToOne
	@JoinColumn(name = "RESOURCE_ID")
	private SecurityResource resource;
	
	//(cascade = {CascadeType.PERSIST,CascadeType.MERGE}) 不级联保存按钮
	@ManyToOne
	@JoinColumn(name = "OPERATION_ID")
	private SecurityOperation operation;
	
	@Column(name = "PERMISSION_NAME", length = 20)
	private String permissionName;
	
	@Column(name = "PERMISSION_CODE", length = 20)
	private String permissionCode;
	
	@OneToMany(mappedBy = "permission",fetch = FetchType.LAZY,cascade = CascadeType.ALL)
	private List<SecurityPermissionAccount> permissionAccounts = new ArrayList<SecurityPermissionAccount>(
			0);
	
	@OneToMany(mappedBy = "permission",fetch = FetchType.LAZY,cascade = CascadeType.ALL)
	private List<SecurityAccountRolePermission> accRolePermissions = new ArrayList<SecurityAccountRolePermission>(
			0);
	
	@OneToMany(mappedBy = "permission",fetch = FetchType.LAZY,cascade = CascadeType.ALL)
	private List<SecurityPermissionRole> permissionRoles = new ArrayList<SecurityPermissionRole>(
			0);

	public SecurityPermission() {
	}

	public SecurityPermission(String permissionId) {
		this.permissionId = permissionId;
	}

	public SecurityPermission(String permissionId, SecurityResource resource, SecurityOperation operation, String permissionName, String permissionCode,
            List<SecurityPermissionAccount> permissionAccounts, List<SecurityAccountRolePermission> accRolePermissions,
            List<SecurityPermissionRole> permissionRoles)
    {
        super();
        this.permissionId = permissionId;
        this.resource = resource;
        this.operation = operation;
        this.permissionName = permissionName;
        this.permissionCode = permissionCode;
        this.permissionAccounts = permissionAccounts;
        this.accRolePermissions = accRolePermissions;
        this.permissionRoles = permissionRoles;
    }

    public String getPermissionId() {
		return this.permissionId;
	}

	public void setPermissionId(String permissionId) {
		this.permissionId = permissionId;
	}

	public SecurityResource getResource() {
		return this.resource;
	}

	public void setResource(SecurityResource resource) {
		this.resource = resource;
	}

	public SecurityOperation getOperation() {
		return this.operation;
	}

	public void setOperation(SecurityOperation operation) {
		this.operation = operation;
	}

	public String getPermissionName() {
		return this.permissionName;
	}

	public void setPermissionName(String permissionName) {
		this.permissionName = permissionName;
	}

	public String getPermissionCode() {
		return permissionCode;
	}

	public void setPermissionCode(String permissionCode) {
		this.permissionCode = permissionCode;
	}

	public List<SecurityPermissionAccount> getPermissionAccounts() {
		return this.permissionAccounts;
	}

	public void setPermissionAccounts(
			List<SecurityPermissionAccount> permissionAccounts) {
		this.permissionAccounts = permissionAccounts;
	}

	public List<SecurityAccountRolePermission> getAccRolePermissions() {
		return this.accRolePermissions;
	}

	public void setAccRolePermissions(
			List<SecurityAccountRolePermission> accRolePermissions) {
		this.accRolePermissions = accRolePermissions;
	}
	
	public List<SecurityPermissionRole> getPermissionRoles()
    {
        return permissionRoles;
    }

    public void setPermissionRoles(List<SecurityPermissionRole> permissionRoles)
    {
        this.permissionRoles = permissionRoles;
    }

    @Override
	public String toString() {
		return "";//BeanHelper.toString(this);
	}
}
